home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-04-16 | 1.9 KB | 90 lines | [TEXT/CWIE] |
- // Progress.h
- // Copyright: © 1994 - 1998 by Apple Computer, Inc., all rights reserved.
-
-
- // a utility to simplify the implementation of progress reporting
-
- #pragma once
- #ifndef Progress_h
- #define Progress_h
-
- #pragma import on
-
- #if PRAGMA_STRUCT_ALIGN
- #pragma options align=power
- #endif
-
-
- #include "IACommon.h"
-
- #include <time.h>
-
- #pragma IA_BEGIN_EXPORTS
-
- /// To use, first create a progress object:
- // Progess progress(updateFreq, progressFunction, data);
- // then create a Phase for each phase of the computation (phases may be nested)
- // Phase thisPhase(<steps>, &progress);
- // for each step of each phase (& sub-phase):
- // progress.Step();
- // and periodically:
- // progress.Check() ? return;
- // the above may be combined with:
- // progress.StepCheck();
-
- class Progress;
-
- class Phase {
- public:
- Phase(uint32 n, Progress* p);
- ~Phase();
-
- uint32 atStep;
- uint32 outOf;
- Phase* parent; // up-link in doubly-linked stack
- Phase* child; // down-link in doubly linked stack
- Progress* progress;
- private:
- Phase(Phase&); // leave copy ctor undefined
- void* operator new(size_t size); // stack allocate only
- };
-
- typedef bool ProgressFn(float percent, void* data);
-
- const float ProgressEpsilon = 0.001f;
-
- class Progress {
- public:
- Progress(clock_t fr, ProgressFn* f, void* d);
- void Step(uint32 increment = 1) { top->atStep += increment; }
- bool Check();
- bool StepCheck(uint32 i = 1) { Step(i); return Check(); }
- void Complete();
-
- Phase* top; // top of stack
- Phase* root; // bottom of stack
-
- void* data;
- private:
-
- clock_t updateFreq;
- clock_t lastUpdateTime;
- float lastUpdatePercent;
- ProgressFn* fn;
-
- float PercentComplete();
-
- Progress(Progress&); // leave copy ctor undefined
- void* operator new(size_t size); // stack allocate only
- };
-
- #pragma IA_END_EXPORTS
-
- #if PRAGMA_STRUCT_ALIGN
- #pragma options align=reset
- #endif
-
- #pragma import reset
-
- #endif
-